package com.easypoi.domain;

import com.easypoi.entity.Person;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author HKC
 */
@Component
@Aspect
public class PasswordAspects {
    @Around("execution(* com.easypoi.service.Person*.select*(..))")
    public Object changePassword(ProceedingJoinPoint pjp) throws Throwable {
        Object obj = pjp.proceed();
        if(obj != null && obj instanceof List){
            List<Person> userList = (List<Person>) obj;
            if(userList != null && userList.size() > 0){
                for (Person temp : userList){
                    temp.setPassword(changeString(temp.getPassword()));
                }
            }
        }
        return obj;
    }

    private String changeString(String str) {
        StringBuffer sb = new StringBuffer();
        if (str != null && str.trim().length() > 0) {
            for (int i = 0; i < str.length(); i++) {
                sb.append('*');
            }
        }
        return sb.toString();
    }
}

